<!DOCTYPE html>
<html lang="en">
<head>
    <title id="Description">This demo showcases some of the functionalities available in
        jqxToolBar's API</title>
    <meta name="description" content="This demo showcases some of the functionalities available in jqxToolBar's API" />
    <link type="text/css" rel="Stylesheet" href="../../jqwidgets/styles/jqx.base.css" />
    <style type="text/css">
        .buttonIcon
        {
            margin: -5px 0 0 -3px;
            width: 16px;
            height: 17px;
        }
    </style>
    <script type="text/javascript" src="../../scripts/jquery-1.11.1.min.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxbuttons.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxscrollbar.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxlistbox.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxdropdownlist.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxcombobox.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxinput.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxnumberinput.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxtoolbar.js"></script>
    <script type="text/javascript" src="../../scripts/demos.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#jqxToolBar").jqxToolBar({
                width: "100%", height: 35, tools: 'toggleButton toggleButton toggleButton | toggleButton | dropdownlist combobox | input |',
                initTools: function (type, index, tool, menuToolIninitialization) {
                    if (type == "toggleButton") {
                        var icon = $("<div class='jqx-editor-toolbar-icon jqx-editor-toolbar-icon-" + theme + " buttonIcon'></div>");
                    }
                    switch (index) {
                        case 0:
                            icon.addClass("jqx-editor-toolbar-icon-bold jqx-editor-toolbar-icon-bold-" + theme);
                            icon.attr("title", "Bold");
                            tool.append(icon);
                            break;
                        case 1:
                            icon.addClass("jqx-editor-toolbar-icon-italic jqx-editor-toolbar-icon-italic-" + theme);
                            icon.attr("title", "Italic");
                            tool.append(icon);
                            break;
                        case 2:
                            icon.addClass("jqx-editor-toolbar-icon-underline jqx-editor-toolbar-icon-underline-" + theme);
                            icon.attr("title", "Underline");
                            tool.append(icon);
                            break;
                        case 3:
                            tool.jqxToggleButton({ width: 80, toggled: true });
                            tool.text("Enabled");
                            tool.on("click", function () {
                                var toggled = tool.jqxToggleButton("toggled");
                                if (toggled) {
                                    tool.text("Enabled");
                                } else {
                                    tool.text("Disabled");
                                }
                            });
                            break;
                        case 4:
                            tool.jqxDropDownList({ width: 130, source: ["<span style='font-family: Courier New;'>Courier New</span>", "<span style='font-family: Times New Roman;'>Times New Roman</span>", "<span style='font-family: Verdana;'>Verdana</span>"], selectedIndex: 1 });
                            break;
                        case 5:
                            tool.jqxComboBox({ width: 50, source: [8, 9, 10, 11, 12, 14, 16, 18, 20], selectedIndex: 3 });
                            break;
                        case 6:
                            tool.jqxInput({ width: 200, placeHolder: "Type here to search..." });
                            break;
                    }
                }
            });

            $("#addToggleButton, #addCustomTool, #disableTool, #enableTool, #destroyTool").jqxButton({ width: 150 });
            $("#position").jqxDropDownList({ width: 150, height: 22, source: ["first", "last"], selectedIndex: 1, autoDropDownHeight: true });
            $("#index").jqxNumberInput({ width: 50, height: 25, decimal: 0, decimalDigits: 0, inputMode: "simple" });

            $("#addToggleButton").click(function () {
                var position = $("#position").jqxDropDownList("val");
                $("#jqxToolBar").jqxToolBar("addTool", "toggleButton", position, false, function (type, tool, menuToolIninitialization) {
                    var width;
                    if (menuToolIninitialization) {
                        // specific setting for minimized tool
                        width = "100%";
                    } else {
                        width = 50;
                    }

                    tool.jqxToggleButton({ width: width, toggled: false });
                    tool.text("Off");
                    tool.on("click", function () {
                        var toggled = tool.jqxToggleButton("toggled");
                        if (toggled) {
                            tool.text("On");
                        } else {
                            tool.text("Off");
                        }
                    });
                });
            });

            var countries = ["Argentina", "Austria", "Canada", "China", "France", "Germany", "Japan", "Mexico", "Spain", "Sweden", "Switzerland", "UK", "USA"];

            $("#addCustomTool").click(function () {
                var position = $("#position").jqxDropDownList("val");
                var country = countries[Math.floor(Math.random() * countries.length)];
                $("#jqxToolBar").jqxToolBar("addTool", "custom", position, false, function (type, tool, menuToolIninitialization) {
                    tool.append("<img src='../../images/" + country + ".png' style='float: left; clear: both;' />");
                    if (menuToolIninitialization) {
                        // specific setting for minimized tool
                        tool.find("img").css("margin-right", "10px");
                        tool.find("img").css("margin-top", "4px");
                        tool.append("<div style='float: left; height: 100%; vertical-align: middle;'>" + country + "</div>");
                    } else {
                        tool.attr("title", "Flag of " + country);
                    }
                });
            });

            $("#disableTool").click(function () {
                var toolIndex = $("#index").val();
                $("#jqxToolBar").jqxToolBar("disableTool", toolIndex, true);
            });

            $("#enableTool").click(function () {
                var toolIndex = $("#index").val();
                $("#jqxToolBar").jqxToolBar("disableTool", toolIndex, false);
            });

            $("#destroyTool").click(function () {
                var toolIndex = $("#index").val();
                $("#jqxToolBar").jqxToolBar("destroyTool", toolIndex);
            });
        });
    </script>
</head>
<body>
    <div id="jqxToolBar">
    </div>
    <div style="margin-top: 50px;">
        <button id="addToggleButton">
            Add a toggle button</button>
        <button id="addCustomTool" style="margin-left: 10px;">
            Add a custom tool</button>
    </div>
    <div style="margin-top: 10px; margin-bottom: 2px; font-size: small; font-family: Verdana;">
        Insert position:</div>
    <div id="position">
    </div>
    <div style="margin-top: 50px;">
        <button id="disableTool">
            Disable tool</button>
        <button id="enableTool" style="margin-left: 10px;">
            Enable tool</button>
        <button id="destroyTool" style="margin-left: 10px;">
            Destroy tool</button>
    </div>
    <div style="margin-top: 10px; margin-bottom: 2px; font-size: small; font-family: Verdana;">
        Tool index:</div>
    <div id="index">
    </div>
</body>
</html>